package com.caishi.lkx.user.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zzw.common.entity.impl.BaseEntity;
import com.caishi.lkx.user.ienum.type.AgentRechargeType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
* @Param:
* @return
* @Author: huangpeng
* @Date: 2021/9/27 14:36
* @Description: 代理商充值
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("cu_agent_recharge")
public class AgentRechargeModel extends BaseEntity<AgentRechargeModel> {

 @Schema(title = "充值金额")
    private Long amount;

    @Schema(title = "充值类型")
    private AgentRechargeType type;

    @Schema(title = "代理商用户ID")
    private String userId;

    private String remark;

   @TableField(exist = false)
   private String createdByName;
   @TableField(exist = false)
   private String rechargeUser;
   @TableField(exist = false)
   private String agentName;

    @Schema(title = "提成金额元")
    @TableField(exist = false)
    private BigDecimal priceYuan;

    public BigDecimal getPriceYuan() {
        if(null == this.amount){
            return BigDecimal.ZERO;
        }
        return new BigDecimal(this.amount).divide(new BigDecimal("100") ,2, RoundingMode.HALF_UP);
    }

    public void setPriceYuan(BigDecimal priceYuan) {
        this.priceYuan = priceYuan;
        if(null != priceYuan){
            this.setAmount(priceYuan.multiply(new BigDecimal("100")).longValue());
        }
    }
}
